package netWork;

import java.io.*;
import java.util.Scanner;

public class UtilAPi {
    //两个方法
    public  static byte[] getByteArray(InputStream inputStream) throws IOException {
        byte[]b = new byte[4096];
        int n = 0;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        while ((n = inputStream.read(b)) != -1){
            baos.write(b,0,n);
        }
        baos.flush();
        byte[]array = baos.toByteArray();
        baos.close();
        return array;
    }
        public static String streamToString(InputStream is) throws Exception {

            StringBuilder builder = new StringBuilder();
            byte[] bytes = new byte[4096];
            int line;
            while ((line = is.read(bytes)) != -1) {
                builder.append(new String(bytes,0,line));
            }
            return builder.toString();

    }
}
